package cms.simmytech.service;

import cms.simmytech.util.HttpResultUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {

	Log log=LogFactory.getLog(MyAccessDeniedHandler.class);
	
	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,
			AccessDeniedException accessDeniedException) throws IOException, ServletException {
		StringBuffer msg = new StringBuffer("请求: ");
        msg.append(request.getRequestURI()).append("权限不足，无法访问系统资源.");
        log.info(msg.toString());
        HttpResultUtil.responseJS(request,response, msg.toString(), 403);
	}

}
